#include "Polygon.h"
#include "_Math.h"

// ---------------------------------------------------------
CPolygon::CPolygon() : mnPointCount(0)
{
}

// ---------------------------------------------------------
CPolygon::~CPolygon()
{
}

// ---------------------------------------------------------
bool CPolygon::AddPoint(Point2D& point)
{
	if (mnPointCount >= MaxPointCount)
	{
		return false;
	}

	mpPointList[mnPointCount++] = point;

	return true;
}

// ---------------------------------------------------------
bool CPolygon::AddPoint(int x, int y)
{
	if (mnPointCount >= MaxPointCount)
	{
		//ASSERT(FALSE);
		return false;
	}

	mpPointList[mnPointCount++] = Point2D(x, y);

	return true;
}

// ---------------------------------------------------------

int CPolygon::VertexCount()
{
	return mnPointCount;
}

void CPolygon::Clear()
{
	mnPointCount = 0;
}
void CPolygon::RotateTransform(int angle)
{
	for(int i = 0; i < VertexCount(); i++)
	{
		mpPointList[i].RotateTransform(angle);
	}
}

void CPolygon::ScaleTransform(int sx, int sy)
{
	for(int i = 0; i < VertexCount(); i++)
	{
		mpPointList[i].x = mpPointList[i].x * sx >> 8;
		mpPointList[i].y = mpPointList[i].y * sy >> 8;
	}
}

void CPolygon::TranslateTransform(int dx, int dy)
{
	for(int i = 0; i < VertexCount(); i++)
	{
		mpPointList[i].TranslateTransform(dx, dy);
	}
}

bool CPolygon::Contain(Point2D& pt)
{
	return CMath::insidePolygon(mnPointCount, mpPointList, pt);
}
